package futbol.tacticas.concursantes.FCAlexB;

public class Rectangulo {

	//Propiedades
	private double[] cA=new double[2];
	private double[] cB=new double[2];
	private double[] cC=new double[2];
	private double[] cD=new double[2];
	private double A;
	private double B;
	private double C;
	private double D;
	private double area;
	
	//Constructor
	public Rectangulo(double aX, double aY, double bX, double bY,double cX,double cY, double dX, double dY){
		this.cA[0]=aX;
		this.cA[1]=aY;
		this.cB[0]=bX;
		this.cB[1]=bY;
		this.cC[0]=cX;
		this.cC[1]=cY;
		this.cD[0]=dX;
		this.cD[1]=dY;
		this.A=Math.sqrt((Math.pow((aX-bX), 2))+(Math.pow((aY-bY), 2)));
		this.B=Math.sqrt((Math.pow((bX-cX), 2))+(Math.pow((bY-cY), 2)));
		this.C=Math.sqrt((Math.pow((cX-dX), 2))+(Math.pow((cY-dY), 2)));
		this.D=Math.sqrt((Math.pow((dX-aX), 2))+(Math.pow((dY-aY), 2)));
		this.area=(Math.sqrt((Math.pow((cX-dX), 2))+(Math.pow((cY-dY), 2))))+(Math.sqrt((Math.pow((bX-cX), 2))*(Math.pow((bY-cY), 2))));//Base*altura
	}

	//Getters y setters
	public double[] getCA() {
		return cA;
	}

	public void setCA(double[] ca) {
		cA = ca;
	}

	public double[] getCB() {
		return cB;
	}

	public void setCB(double[] cb) {
		cB = cb;
	}

	public double[] getCC() {
		return cC;
	}

	public void setCC(double[] cc) {
		cC = cc;
	}

	public double[] getCD() {
		return cD;
	}

	public void setCD(double[] cd) {
		cD = cd;
	}

	public double getA() {
		return A;
	}

	
	public double getArea() {
		return area;
	}

	public double getB() {
		return B;
	}

	public double getC() {
		return C;
	}

	public double getD() {
		return D;
	}
	
	//Mtodo para saber si un punto (x,y) esta en el rectngulo
	public boolean isInRectangulo(double x, double y){
		Triangulo mitadA = new Triangulo(this.getCA()[0], this.getCA()[1], this.getCC()[0], this.getCC()[1], this.getCD()[0], this.getCD()[1]);	
		Triangulo tercioAA = new Triangulo(this.getCA()[0], this.getCA()[1], this.getCD()[0], this.getCD()[1], x, y);
		Triangulo tercioAB = new Triangulo(this.getCA()[0], this.getCA()[1], this.getCC()[0], this.getCC()[1], x, y);
		Triangulo tercioAC = new Triangulo(this.getCC()[0], this.getCC()[1], this.getCD()[0], this.getCD()[1], x, y);
		//System.out.println("mitadA"+tercioAA.getArea()+","+tercioAB.getArea()+","+tercioAC.getArea()+","+mitadA.getArea());
		if ((tercioAA.getArea()+tercioAB.getArea()+tercioAC.getArea())==mitadA.getArea()){
			//System.out.print("MIIIIAMAIIMAMAIAM");
			return true;
		}
		Triangulo mitadB = new Triangulo(this.getCA()[0], this.getCA()[1], this.getCB()[0], this.getCB()[1], this.getCC()[0], this.getCC()[1]);
		Triangulo tercioBA = new Triangulo(this.getCA()[0], this.getCA()[1], this.getCB()[0], this.getCB()[1], x, y);
		Triangulo tercioBB = new Triangulo(this.getCB()[0], this.getCB()[1], this.getCC()[0], this.getCC()[1], x, y);
		Triangulo tercioBC = new Triangulo(this.getCA()[0], this.getCA()[1], this.getCC()[0], this.getCC()[1], x, y);
		//System.out.println("mitadB"+tercioBA.getArea()+","+tercioBB.getArea()+","+tercioBC.getArea()+","+mitadB.getArea());
		if ((tercioBA.getArea()+tercioBB.getArea()+tercioBC.getArea())==mitadB.getArea()){
			//System.out.print("MIIIIAMAIIMAMAIAM");
			return true;
		}
		return false;
	}
}
